from flask import Blueprint
from .main import user
from flask import request
import logging

user = Blueprint("user",__name__, url_prefix='/user')

#TODO 获取微信用户信息
@user.route('/get_info')
def get_user_info():
    form = request.form if request.method == 'POST' else request.args
    code = form.get('code')
    key = form.get('key')
    iv = form.get('iv')
    return user.get_user_info(code=code,key=key,iv=iv)

#TODO 用户绑定教务网账号
@user.route('/bind')
def bind():
    form = request.form if request.method == 'POST' else request.args
    openid = form.get('openid','')
    sno = form.get('yktid',0)
    spw = form.get('passwd','')
    res = user.bind(openid=openid,sno=sno,spw=spw)
    if res:
        return {'status':200,'message':'ok'}
    else:
        return {'status':400,'message':'error'}

#TODO 根据学号从教务网同步信息
@user.route('/syn_info')
def syn_info():
    return {'status': 200, 'message': 'ok'}
